package Test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import static java.lang.Thread.sleep;

/**
 * 作业练习题
 */
public class test_01 {
    public static void main1(String[] args) throws InterruptedException {
//        test01();
        test02();
    }

    private static void test02() throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("selenium");
        // 点击百度按钮
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000); // 强制等待
        // 获取结果页任意文本信息并打印。
        WebElement text = webDriver.findElement(By.xpath("//*[@id=\"tsn_inner\"]/div[2]/span"));
        System.out.println(text.getText());
    }

    public static void test01() {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://mail.163.com/");
        webDriver.findElement(By.xpath("//*[@id=\"auto-id-1684059976304\"]"))
                .sendKeys("rrrichsy");
        webDriver.findElement(By.xpath("//*[@id=\"auto-id-1684059976307\"]"))
                .sendKeys("SYsy002123789");
        webDriver.findElement(By.cssSelector("#dologin")).click();
        webDriver.quit();
    }
}
